package org.csu.demopetstore.Service;

import org.csu.demopetstore.Persistence.OrderMapper;
import org.csu.demopetstore.entity.LineItem;
import org.csu.demopetstore.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

    public void insertOrder(Order order){
        orderMapper.insertOrder(order);
    }

    public Order getOrderByID(int orderId){
        return orderMapper.getOrderByID(orderId);
    }

    public List<Order> getListOrder(String username){
        return orderMapper.getListOrder(username);
    }

    public List<LineItem> getLineItem(int orderId){
        return orderMapper.getLineItem(orderId);
    }

    public void insertLineItem(LineItem lineItem){
        orderMapper.insertLineItem(lineItem);
    }

    public int getCount(){
        return orderMapper.getCount();
    }

    public void insertOrderStatus(Order order){
        int num = order.getLineItems().size();
        orderMapper.insertOrderStatus(order.getOrderId(),num,order.getOrderDate(),order.getStatus());
    }
}
